define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'item/index' + location.search,
                    add_url: 'item/add',
                    edit_url: 'item/edit',
                    del_url: 'item/del',
                    multi_url: 'item/multi',
                    table: 'item',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'name', title: __('Name')},
                        // {field: 'shop_id', title: __('Shop_id')},
                        {field: 'category_id', title: __('Category_id'),visible:false},
                        {field: 'category.name', title: __('Category_id')},
                        // {field: 'brand_id', title: __('Brand_id')},
                        {field: 'tag', title: __('Tag'), searchList: {"1":__('Tag 1'),"2":__('Tag 2'),"3":__('Tag 3'),"4":__('Tag 4'),"5":__('Tag 5')}, operate:'FIND_IN_SET', formatter: Table.api.formatter.label},
                        {field: 'addr', title: __('Addr')},
                        // {field: 'description', title: __('Description')},
                        {field: 'original_price', title: __('Original_price'), operate:'BETWEEN'},
                        {field: 'current_price', title: __('Current_price'), operate:'BETWEEN'},
                        // {field: 'ship_fee', title: __('Ship_fee'), operate:'BETWEEN'},
                        {field: 'views', title: __('Views')},
                        {field: 'storage_num', title: __('Storage_num')},
                        {field: 'sold_num', title: __('Sold_num')},
                        // {field: 'extra', title: __('Extra')},
                        {field: 'images', title: __('Images'), events: Table.api.events.image, formatter: Table.api.formatter.images},
                        // {field: 'thumbs', title: __('Thumbs')},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        // {field: 'qr_url', title: __('Qr_url'), formatter: Table.api.formatter.url},
                        {field: 'commission_amount', title: __('Commission_amount'), operate:'BETWEEN'},
                        {field: 'status', title: __('Status'), searchList: {"0":__('Status 0'),"1":__('Status 1'),"-1":__('Status -1')}, formatter: Table.api.formatter.status},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});